﻿Public Class Form_Entry_Upload_Dokumen
    Inherits System.Web.UI.Page
    Dim koneksidataakses12 As New KoneksiDataAkses
    Dim kueri As String

    Sub bersih()
        textbox1.Text = ""
        textbox2.Text = ""
        textbox3.Text = ""
        textbox4.Text = ""
        textbox5.Text = ""
        textbox6.Text = ""
        GridView1.SelectedIndex = -1
        dropdownlist1.DataBind()
        dropdownlist2.DataBind()
        dropdownlist3.DataBind()
        dropdownlist4.DataBind()
        dropdownlist5.DataBind()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        tabel1.Visible = False
    End Sub


    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        If e.CommandName = "btnCopy" Then
            bersih()
            textbox1.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(2).Text
            textbox2.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(3).Text
            textbox3.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(8).Text
            textbox4.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(4).Text
            textbox5.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(9).Text
            'textbox6.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(2).Text
            'If GridView1.Rows(e.CommandArgument.ToString).Cells(3).Text = "Aktif" Then
            '    dropdownlist1.SelectedValue = 0
            'ElseIf GridView1.Rows(e.CommandArgument.ToString).Cells(3).Text = "Pasif" Then
            '    dropdownlist1.SelectedValue = 1
            'End If
            dropdownlist1.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(1).Text
            dropdownlist2.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(6).Text
            dropdownlist3.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(7).Text
            dropdownlist4.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(10).Text
            dropdownlist5.Text = GridView1.Rows(e.CommandArgument.ToString).Cells(11).Text

            System.Web.HttpContext.Current.Session("status_action") = True
            tabel1.Visible = True
        End If
    End Sub

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles GridView1.SelectedIndexChanged
        textbox1.Text = GridView1.SelectedRow.Cells(2).Text
        textbox2.Text = GridView1.SelectedRow.Cells(3).Text
        textbox3.Text = GridView1.SelectedRow.Cells(8).Text
        textbox4.Text = GridView1.SelectedRow.Cells(4).Text
        textbox5.Text = GridView1.SelectedRow.Cells(9).Text
        'If GridView1.Rows(e.CommandArgument.ToString).Cells(3).Text = "Aktif" Then
        '    dropdownlist1.SelectedValue = 0
        'ElseIf GridView1.Rows(e.CommandArgument.ToString).Cells(3).Text = "Pasif" Then
        '    dropdownlist1.SelectedValue = 1
        'End If
        dropdownlist1.Text = GridView1.SelectedRow.Cells(1).Text
        dropdownlist2.Text = GridView1.SelectedRow.Cells(6).Text
        dropdownlist3.Text = GridView1.SelectedRow.Cells(7).Text
        dropdownlist4.Text = GridView1.SelectedRow.Cells(10).Text
        dropdownlist5.Text = GridView1.SelectedRow.Cells(11).Text
        System.Web.HttpContext.Current.Session("status_action") = False

        tabel1.Visible = True

    End Sub

    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
        bersih()
        tabel1.Visible = True
        System.Web.HttpContext.Current.Session("status_action") = True
    End Sub

    Protected Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button2.Click

        If Session("status_action") = True Then

            If koneksidataakses12.cekDuplikat("TB_SKA_DOKUMEN", "no_dokumen", textbox1.Text) = 0 Then
                kueri = "insert into TB_SKA_DOKUMEN (id_arsip,no_dokumen,nama_dokumen,perihal,tanggal,id_jenis_dok,id_divisi,pihak_pengirim,pihak_dituju,id_bidang_dok,id_sifat_dok) values((select id_arsip from TB_SKA_ARSIP where id_arsip='" + dropdownlist1.Text + "'),'" + textbox1.Text + "','" + textbox2.Text + "','" + textbox4.Text + "',convert(datetime,'" + textbox6.Text + "',103),(select id_jenis_dok from TB_MST_JENIS_DOK where jenis_dok= '" + dropdownlist2.Text + "'),(select id_divisi from TB_MST_DIVISI where kode_divisi='" + dropdownlist3.Text + "'),'" + textbox3.Text + "','" + textbox5.Text + "',(select id_bidang_dok from TB_MST_BIDANG_DOK where bidang_dok='" + dropdownlist4.Text + "'),(select id_sifat_dok from TB_SKA_SIFAT_DOK where sifat_dok='" + dropdownlist5.Text + "'))"
                koneksidataakses12.EksekusiNonQuery(kueri)
                GridView1.DataBind()
                bersih()
                tabel1.Visible = False
            Else
                Response.Write("ada data yang sama")
            End If
        ElseIf Session("status_action") = False Then
            kueri = "update TB_SKA_DOKUMEN set id_arsip=(select id_arsip from TB_SKA_ARSIP where id_arsip='" + dropdownlist1.Text + "'),no_dokumen='" + textbox1.Text + "',nama_dokumen='" + textbox2.Text + "',perihal='" + textbox4.Text + "',tanggal=convert(datetime,'" + textbox6.Text + "',103),id_jenis_dok=(select id_jenis_dok from TB_MST_JENIS_DOK where jenis_dok= '" + dropdownlist2.Text + "'),id_divisi=(select id_divisi from TB_MST_DIVISI where kode_divisi='" + dropdownlist3.Text + "'),pihak_pengirim='" + textbox3.Text + "',pihak_dituju='" + textbox5.Text + "',id_bidang_dok=(select id_bidang_dok from TB_MST_BIDANG_DOK where bidang_dok='" + dropdownlist4.Text + "'),id_sifat_dok=(select id_sifat_dok from TB_SKA_SIFAT_DOK where sifat_dok='" + dropdownlist5.Text + "') where id_dokumen=" + GridView1.SelectedRow.Cells(0).Text + ""
            koneksidataakses12.EksekusiNonQuery(kueri)
            GridView1.DataBind()
            bersih()
            tabel1.Visible = False
        End If
    End Sub

    Protected Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles GridView1.PageIndexChanged
        bersih()
    End Sub

    Protected Sub button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button3.Click
        bersih()
        tabel1.Visible = False
    End Sub

End Class